package com.newhero.app.report.web.controller;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.junit.internal.runners.model.EachTestNotifier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.newhero.app.report.persistence.entity.Disclose;
import com.newhero.app.report.persistence.entity.Post;
import com.newhero.app.report.persistence.entity.ReportKind;
import com.newhero.app.report.persistence.entity.ReportRegion;
import com.newhero.app.report.persistence.entity.ReportResponse;
import com.newhero.app.report.service.IDiscloseService;
import com.newhero.app.report.service.IPostService;
import com.newhero.app.report.service.IReportKindService;
import com.newhero.app.report.service.IReportRegionService;
import com.newhero.app.report.service.IReportResponseService;
import com.newhero.app.report.utils.DESFileUtil;
import com.newhero.app.report.utils.DesModleUtils;
import com.newhero.app.report.utils.StringSubStr;
import com.newhero.product.common.controller.BaseController;
import com.newhero.product.common.mybatis.mapper.EntityWrapper;
import com.newhero.product.common.mybatis.plugins.Page;
import com.newhero.product.common.mybatis.toolkit.IdWorker;
import com.newhero.product.common.util.GTime;
import com.newhero.product.common.util.StringUtils;
import com.newhero.product.common.vo.Json;
import com.newhero.product.module.sys.model.Organ;
import com.newhero.product.module.sys.service.IOrganService;
import com.newhero.product.util.ExportUtil;

 /**
 * @ClassName: DiscloseController
 * @Description: 访问控制类
 * @author zlf
 * @date 2018-09-07
 */
@Controller
@RequestMapping("/disclose")
public class DiscloseController extends BaseController {
    
    @Autowired 
    private IDiscloseService discloseServiceImpl;
    
    @Autowired 
    private IPostService postServiceImpl;
    
    @Autowired 
    private IReportKindService reportKindServiceImpl;
    
    @Autowired 
    private IReportRegionService reportRegionServiceImpl;
    
    @Autowired 
    private IOrganService organServiceImpl;
    
    @Autowired 
    private IReportResponseService reportResponseServiceImpl;
    
    /**
     * 被举报人列表   （主页面）
     * @return
     */
	@RequestMapping(value = "/mainDisclose", method = RequestMethod.GET)
	public String mainDisclose(HttpServletRequest request) {
		
		return "/report/disclose/mainDisclose";
	}
    /**
     * 举报人列表页面
     * @return
     */    
	@RequestMapping(value = "/discloseList", method ={RequestMethod.GET,RequestMethod.POST })
	public String discloseList(
			@RequestParam(value = "page", defaultValue = "1", required = true) int page,// 页号
			@RequestParam(value = "rows", defaultValue = "" + _ROWS_PER_PAGE, required = true) int rows,// 每页显示的记录条数
			@RequestParam(value = "orderField", defaultValue = "disclose_id", required = true) String orderField,
			@RequestParam(value = "isAsc", defaultValue = "0", required = true) int isAsc,//1-代表true;0-代表false
			@RequestParam(value = "state", defaultValue = "0", required = true) int state,//0-代表未读;1-代表已读
			Disclose disclose,
			HttpServletRequest request, HttpServletResponse response, ModelMap model) {
		Page<Disclose> p = new Page<Disclose>();
		p.setCurrent(page);
		p.setSize(rows);
		p.setOrderByField(orderField);
		if(isAsc==0){
			p.setAsc(false);
		}else{
			p.setAsc(true);
		}
		
		String mxcode = "";
		if(StringUtils.isNotBlank(disclose.getMxcode())){
			mxcode = disclose.getMxcode();
		}else{
			String organID = super.getOrganID();
			Organ organ  = organServiceImpl.selectById(organID);
			mxcode = organ.getOrganCode();
			model.addAttribute("mxcode",mxcode);
		}
		
		EntityWrapper<Disclose> entityWrapper = new EntityWrapper<Disclose>();
		
    	if(StringUtils.isNotBlank(disclose.getKindId())){
			try {
				entityWrapper.eq("kind_id", DESFileUtil.encryptStr(disclose.getKindId()));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
    	model.addAttribute("kindId", disclose.getKindId());
    	
    	String regionCode = "";
		if(StringUtils.isNotBlank(disclose.getMxcode())){
			regionCode = disclose.getMxcode();
			try {
				entityWrapper.eq("mxcode", DESFileUtil.encryptStr(regionCode));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}else{
			regionCode = mxcode;
			try {
				String userId = this.getUserID();
				String findAllFlag = this.getConfigWithDefault(userId,"0");
				//判断管理员权限是否 能看到所有的被举报信息 ，是 :1 否:0 
				if("0".equals(findAllFlag)){
					entityWrapper.eq("mxcode", DESFileUtil.encryptStr(mxcode));
				}
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		//是否受理：0：未受理1： 已受理 2:已导出
		//entityWrapper.eq("state",state);
		if(state == 0){
			entityWrapper.eq("state", state);
		}else{
			entityWrapper.andNew("state = '"+state+"' or state =  '2' ");
		}
		model.addAttribute("state",state);
		model.addAttribute("mxcode",mxcode);
		model.addAttribute("regionCode",regionCode);
		
    	entityWrapper.eq("disclose_type", "0");
    	entityWrapper.eq("remove_flag","0");
    	entityWrapper.orderBy("date_order", false);
    	
		p = discloseServiceImpl.selectPage(p, entityWrapper);
		List<Disclose>  disclosesList= new ArrayList<Disclose>();
		List <Disclose> records = p.getRecords();
		for(int i = 0;i < records.size();i++){
			Disclose dis = records.get(i);
			Disclose disDecrypt = DiscloseEncryptAndDecrypt(dis,"1");
			disclosesList.add(disDecrypt);
		}
		p.setRecords(disclosesList);
		model.addAttribute("data", p);
		model.addAttribute("orderField", orderField);
		model.addAttribute("isAsc", isAsc);
		//所有举报组织列表
		EntityWrapper<ReportRegion> regionWrapper = new EntityWrapper<ReportRegion>();
		regionWrapper.orderBy("region_oder",false);
		List<ReportRegion> reportRegionList = reportRegionServiceImpl.selectList(regionWrapper);
		request.setAttribute("reportRegionList", reportRegionList);
		
		return "/report/disclose/discloseList";
	}
	
	
	 /**
     * 被举报单位列表   （主页面）
     * @return
     */
	@RequestMapping(value = "/mainDiscloseUnit", method = RequestMethod.GET)
	public String mainDiscloseUnit(HttpServletRequest request) {
		
		return "/report/disclose/mainDiscloseUnit";
	}
	/**
     * 举报单位列表页面
     * @return
     */    
	@RequestMapping(value = "/discloseUnitList", method ={RequestMethod.GET,RequestMethod.POST })
	public String discloseUnitList(
			@RequestParam(value = "page", defaultValue = "1", required = true) int page,// 页号
			@RequestParam(value = "rows", defaultValue = "" + _ROWS_PER_PAGE, required = true) int rows,// 每页显示的记录条数
			@RequestParam(value = "orderField", defaultValue = "disclose_id", required = true) String orderField,
			@RequestParam(value = "isAsc", defaultValue = "0", required = true) int isAsc,//1-代表true;0-代表false
			@RequestParam(value = "state", defaultValue = "0", required = true) int state,//0-代表未读;1-代表已读
			Disclose disclose,
			HttpServletRequest request, HttpServletResponse response, ModelMap model) {
		Page<Disclose> p = new Page<Disclose>();
		p.setCurrent(page);
		p.setSize(rows);
		p.setOrderByField(orderField);
		if(isAsc==0){
			p.setAsc(false);
		}else{
			p.setAsc(true);
		}
		String organID = super.getOrganID();
		Organ organ  = organServiceImpl.selectById(organID);
		String mxcode = organ.getOrganCode();
		
		
		EntityWrapper<Disclose> entityWrapper = new EntityWrapper<Disclose>();
		
    	if(StringUtils.isNotBlank(disclose.getKindId())){
			try {
				entityWrapper.like("kind_id", DESFileUtil.encryptStr(disclose.getKindId()));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
    	model.addAttribute("kindId", disclose.getKindId());
    	
    	String regionCode = "";
		if(StringUtils.isNotBlank(disclose.getMxcode())){
			regionCode = disclose.getMxcode();
			try {
				entityWrapper.eq("mxcode", DESFileUtil.encryptStr(regionCode));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}else{
			regionCode = mxcode;
			try {
				String userId = this.getUserID();
				String findAllFlag = this.getConfigWithDefault(userId,"0");
				//判断管理员权限是否 能看到所有的被举报信息 ，是 :1 否:0 
				if("0".equals(findAllFlag)){
					entityWrapper.eq("mxcode", DESFileUtil.encryptStr(mxcode));
				}
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		//是否受理：0：未受理1： 已受理 2:已导出
		if(state == 0){
			entityWrapper.eq("state", state);
		}else{
			entityWrapper.andNew("state = '"+state+"' or state =  '2' ");
		}
		
		model.addAttribute("state",state);
		
		model.addAttribute("mxcode",mxcode);
		model.addAttribute("regionCode",regionCode);
		
    	entityWrapper.eq("disclose_type", "1");
    	entityWrapper.eq("remove_flag","0");
    	entityWrapper.orderBy("date_order", false);
		p = discloseServiceImpl.selectPage(p, entityWrapper);
		List<Disclose>  disclosesList= new ArrayList<Disclose>();
		
		List <Disclose> records = p.getRecords();
		for(int i = 0;i < records.size();i++){
			Disclose dis = records.get(i);
			Disclose disDecrypt = DiscloseEncryptAndDecrypt(dis,"1");
			disclosesList.add(disDecrypt);
		}
		p.setRecords(disclosesList);
		model.addAttribute("data", p);
		model.addAttribute("orderField", orderField);
		model.addAttribute("isAsc", isAsc);
		//所有举报组织列表
		EntityWrapper<ReportRegion> regionWrapper = new EntityWrapper<ReportRegion>();
		regionWrapper.orderBy("region_oder",true);
		List<ReportRegion> reportRegionList = reportRegionServiceImpl.selectList(regionWrapper);
		request.setAttribute("reportRegionList", reportRegionList);
		return "/report/disclose/discloseUnitList";
	}
	
	
    /**
     * 举报人（编辑）表单页面
     * @return
     */
	@RequestMapping(value = "/discloseForm", method = RequestMethod.GET)
	public String discloseForm(String discloseId,String regionCode, HttpServletRequest request) {
		
		//信息种类
		EntityWrapper<ReportKind> reportKindWrapper = new EntityWrapper<ReportKind>();
		reportKindWrapper.orderBy("kind_no",true);
		List<ReportKind> reportKindList = reportKindServiceImpl.selectList(reportKindWrapper);
		request.setAttribute("reportKindList", reportKindList);
		
		//所有举报组织列表
		EntityWrapper<ReportRegion> regionWrapper = new EntityWrapper<ReportRegion>();
		regionWrapper.orderBy("region_oder",true);
		List<ReportRegion> reportRegionList = reportRegionServiceImpl.selectList(regionWrapper);
		request.setAttribute("reportRegionList", reportRegionList);
		
		//级别
		EntityWrapper<Post> postWrapper = new EntityWrapper<Post>();
		postWrapper.eq("post_type","people");
		postWrapper.orderBy("post_no",true);
		List<Post> postList = postServiceImpl.selectList(postWrapper);
		request.setAttribute("postList", postList);
		
		if (discloseId != null && !"".equals(discloseId)) {
			request.setAttribute("discloseId", discloseId);
			Disclose dis = discloseServiceImpl.selectById(discloseId);
			Disclose disclose = DiscloseEncryptAndDecrypt(dis,"1");
			if(disclose.getMainContent1()!=null){
				disclose.setMainContent(disclose.getMainContent()+disclose.getMainContent1());
				if(disclose.getMainContent2()!=null){
					disclose.setMainContent(disclose.getMainContent()+disclose.getMainContent2());
					if(disclose.getMainContent3()!=null){
						disclose.setMainContent(disclose.getMainContent()+disclose.getMainContent3());
					}
				}
			}
		 request.setAttribute("formData",disclose);
		 request.setAttribute("reportedSex", "1");
		} else {
		    Map<String, Object> map = new HashMap<String, Object>();
			if(StringUtils.isNotBlank(regionCode)){
				ReportRegion reportRegion = reportRegionServiceImpl.selectById(regionCode);
				map.put("mxcode", reportRegion.getRegionCode());
				map.put("mxname", reportRegion.getRegionName());
			}
			request.setAttribute("discloseId", "");
			map.put("discloseType", "0");
			request.setAttribute("formData", map);
		}
		return "/report/disclose/discloseForm";
	}
	
	/**
     * 举报人查看页面
     * @return
     */
	@RequestMapping(value = "/discloseSeeForm", method = RequestMethod.GET)
	public String discloseSeeForm(String discloseId,String regionCode, HttpServletRequest request) {
		//信息种类
		EntityWrapper<ReportKind> reportKindWrapper = new EntityWrapper<ReportKind>();
		reportKindWrapper.orderBy("kind_no",true);
		List<ReportKind> reportKindList = reportKindServiceImpl.selectList(reportKindWrapper);
		request.setAttribute("reportKindList", reportKindList);
		
		//所有举报组织列表
		EntityWrapper<ReportRegion> regionWrapper = new EntityWrapper<ReportRegion>();
		regionWrapper.orderBy("region_oder",true);
		List<ReportRegion> reportRegionList = reportRegionServiceImpl.selectList(regionWrapper);
		request.setAttribute("reportRegionList", reportRegionList);
		
		//级别
		EntityWrapper<Post> postWrapper = new EntityWrapper<Post>();
		
		postWrapper.eq("post_type","people");
		postWrapper.orderBy("post_no",true);
		List<Post> postList = postServiceImpl.selectList(postWrapper);
		request.setAttribute("postList", postList);
		
		if (discloseId != null && !"".equals(discloseId)) {
			request.setAttribute("discloseId", discloseId);
			Disclose dis = discloseServiceImpl.selectById(discloseId);
			//更新举报状态
			dis.setState(1);
			discloseServiceImpl.updateById(dis);
			
			Disclose disclose = DiscloseEncryptAndDecrypt(dis,"1");
			if(disclose.getMainContent1()!=null){
				disclose.setMainContent(disclose.getMainContent()+disclose.getMainContent1());
				if(disclose.getMainContent2()!=null){
					disclose.setMainContent(disclose.getMainContent()+disclose.getMainContent2());
					if(disclose.getMainContent3()!=null){
						disclose.setMainContent(disclose.getMainContent()+disclose.getMainContent3());
					}
				}
			}
			
			request.setAttribute("formData",disclose);
			request.setAttribute("reportedSex", "1");
		} else {
		    Map<String, Object> map = new HashMap<String, Object>();
			if(StringUtils.isNotBlank(regionCode)){
				ReportRegion reportRegion = reportRegionServiceImpl.selectById(regionCode);
				map.put("mxcode", reportRegion.getRegionCode());
				map.put("mxname", reportRegion.getRegionName());
			}
			request.setAttribute("discloseId", "");
			request.setAttribute("formData", map);
		}
		return "/report/disclose/seeForm";
	}
	
	/**
     * 举报单位（新增|编辑）表单页面
     * @return
     */
	@RequestMapping(value = "/discloseUnitForm", method = RequestMethod.GET)
	public String discloseUnitForm(String discloseId,String regionCode, HttpServletRequest request) {
		
		
		//信息种类
		EntityWrapper<ReportKind> reportKindWrapper = new EntityWrapper<ReportKind>();
		reportKindWrapper.orderBy("kind_no",true);
		List<ReportKind> reportKindList = reportKindServiceImpl.selectList(reportKindWrapper);
		request.setAttribute("reportKindList", reportKindList);
		
		//所有举报组织列表
		EntityWrapper<ReportRegion> regionWrapper = new EntityWrapper<ReportRegion>();
		regionWrapper.orderBy("region_oder",true);
		List<ReportRegion> reportRegionList = reportRegionServiceImpl.selectList(regionWrapper);
		request.setAttribute("reportRegionList", reportRegionList);
		
		//级别
		EntityWrapper<Post> postWrapper = new EntityWrapper<Post>();
		postWrapper.eq("post_type","unit");
		postWrapper.orderBy("post_no",true);
		List<Post> postList = postServiceImpl.selectList(postWrapper);
		request.setAttribute("postList", postList);
		
		if (discloseId != null && !"".equals(discloseId)) {
			request.setAttribute("discloseId", discloseId);
			Disclose disclose = discloseServiceImpl.selectById(discloseId);
			if(disclose.getMainContent1()!=null){
				disclose.setMainContent(disclose.getMainContent()+disclose.getMainContent1());
				if(disclose.getMainContent2()!=null){
					disclose.setMainContent(disclose.getMainContent()+disclose.getMainContent2());
					if(disclose.getMainContent3()!=null){
						disclose.setMainContent(disclose.getMainContent()+disclose.getMainContent3());
					}
				}
			}
			Disclose dis = DiscloseEncryptAndDecrypt(disclose,"1");
		  request.setAttribute("formData",dis);
		  request.setAttribute("reportedSex", "1");
		} else {
		    Map<String, Object> map = new HashMap<String, Object>();
			if(StringUtils.isNotBlank(regionCode)){
				ReportRegion reportRegion = reportRegionServiceImpl.selectById(regionCode);
				map.put("mxcode", reportRegion.getRegionCode());
				map.put("mxname", reportRegion.getRegionName());
			}
			request.setAttribute("discloseId", "");
			map.put("discloseType", "1");
			request.setAttribute("formData", map);
		}
		return "/report/disclose/discloseUnitForm";
	}
	
	/**
     * 举报单位（查看）表单页面
     * @return
     */
	@RequestMapping(value = "/seeUnitForm", method = RequestMethod.GET)
	public String seeUnitForm(String discloseId,String regionCode, HttpServletRequest request) {
		
		
		//信息种类
		EntityWrapper<ReportKind> reportKindWrapper = new EntityWrapper<ReportKind>();
		reportKindWrapper.orderBy("kind_no",true);
		List<ReportKind> reportKindList = reportKindServiceImpl.selectList(reportKindWrapper);
		request.setAttribute("reportKindList", reportKindList);
		
		//所有举报组织列表
		EntityWrapper<ReportRegion> regionWrapper = new EntityWrapper<ReportRegion>();
		regionWrapper.orderBy("region_oder",true);
		List<ReportRegion> reportRegionList = reportRegionServiceImpl.selectList(regionWrapper);
		request.setAttribute("reportRegionList", reportRegionList);
		
		//级别
		EntityWrapper<Post> postWrapper = new EntityWrapper<Post>();
		postWrapper.eq("post_type","unit");
		postWrapper.orderBy("post_no",true);
		List<Post> postList = postServiceImpl.selectList(postWrapper);
		request.setAttribute("postList", postList);
		
		if (discloseId != null && !"".equals(discloseId)) {
			
			request.setAttribute("discloseId", discloseId);
			Disclose dis = discloseServiceImpl.selectById(discloseId);
			//更新举报状态
			dis.setState(1);
			discloseServiceImpl.updateById(dis);
			
			Disclose disclose = DiscloseEncryptAndDecrypt(dis,"1");
			if(disclose.getMainContent1()!=null){
				disclose.setMainContent(disclose.getMainContent()+disclose.getMainContent1());
				if(disclose.getMainContent2()!=null){
					disclose.setMainContent(disclose.getMainContent()+disclose.getMainContent2());
					if(disclose.getMainContent3()!=null){
						disclose.setMainContent(disclose.getMainContent()+disclose.getMainContent3());
					}
				}
			}
		  request.setAttribute("formData",disclose);
		  request.setAttribute("reportedSex", "1");
		} else {
		    Map<String, Object> map = new HashMap<String, Object>();
			if(StringUtils.isNotBlank(regionCode)){
				ReportRegion reportRegion = reportRegionServiceImpl.selectById(regionCode);
				map.put("mxcode", reportRegion.getRegionCode());
				map.put("mxname", reportRegion.getRegionName());
			}
			request.setAttribute("discloseId", "");
			map.put("discloseType", "1");
			request.setAttribute("formData", map);
		}
		return "/report/disclose/seeUnitForm";
	}
	
    /**
     * 表单保存
     * @return
     */
	@RequestMapping(value = "/discloseSave", method = RequestMethod.POST)
	public String discloseSave(
			String discloseId, Disclose disclose, 
			HttpServletRequest request,HttpServletResponse response, ModelMap model) {
		
		//创建人
		String username = this.getUserName();
		//创建人ID
		String userId = this.getUserID();
		String postId = "";
		//级别名称
		String postName = "";
		if((disclose.getDiscloseType() != null) && (0 == disclose.getDiscloseType())){
			postId = disclose.getReportedLevel();
		}else{
			postId = disclose.getReportedUnitLevel();
		}
		postName = postServiceImpl.selectById(postId).getPostName();

		String kindName = "";
		if(!"".equals(disclose.getKindId())){
			kindName = reportKindServiceImpl.selectById(disclose.getKindId()).getKindName();
		}
		
		String conStr = disclose.getMainContent();
		if(conStr.length() > 2500){
			conStr = conStr.substring(0, 2500);
		}
		if(conStr!=null){
			int sublen =3800;
			disclose.setMainContent(StringSubStr.getContent(conStr, sublen, 1));
			disclose.setMainContent1(StringSubStr.getContent(conStr, sublen, 2));
			
			String str1 = StringSubStr.getContent(conStr, sublen, 2);
			String str2 = "";
			if(str1.length() > 0 ){
				disclose.setMainContent2(StringSubStr.getContent(str1, 1900, 1));
				str2 = StringSubStr.getContent(str1, 1900, 1);
			}
			if(str2.length() > 0){
				
				disclose.setMainContent3(StringSubStr.getContent(str1, 900, 1));
			}
			
		}
		disclose.setKindName(kindName);
		disclose.setLevelName(postName);
		try {
			if (!StringUtils.isBlank(discloseId)) {
				model.addAttribute("flag", "数据修改成功！");
				Disclose dis = DiscloseEncryptAndDecrypt(disclose,"0");
		        //举报人Ip
		    	String ip = StringSubStr.getRealIp();
		    	dis.setDisIp(DESFileUtil.encryptStr(ip));
				discloseServiceImpl.updateById(dis);
			} else {
				model.addAttribute("flag", "数据添加成功！");
				//举报事件时间
				//String ctime = GTime.getNormalTime();
				String ctime = GTime.getTime(GTime.YYYY_MM_DD);
				//当前年
				Calendar date = Calendar.getInstance();
		        String year = String.valueOf(date.get(Calendar.YEAR));
		        disclose.setYear(year);
				//自动生成ID查询码
		        String guid = IdWorker.get32UUID();
		        disclose.setReportCode(guid);
		        //ctime = DESFileUtil.encryptStr(ctime);
		        disclose.setDisDate(ctime);
		        disclose.setDateOrder(GTime.getTime(GTime.YYMMDDhhmmss));
		        //举报人Ip
		    	String ip = StringSubStr.getRealIp();
		    	disclose.setDisIp(DESFileUtil.encryptStr(ip));
		        disclose.setState(0);//是否受理 0:未受理(未读)  1:已受理(已读)
		        disclose.setRemoveFlag(0);//是否删除 1:未删除  1:已删除
		        
		        Disclose dis = DiscloseEncryptAndDecrypt(disclose,"0");
				discloseServiceImpl.insert(dis);
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e);
		}
		if((disclose.getDiscloseType() != null) && (0 == disclose.getDiscloseType())){
			return "redirect:discloseList";
		}else{
			return "redirect:discloseUnitList";
		}
	}
	
	/**
	 * 信息转储
	 * @param id
	 * @param mxcode
	 * @param mxname
	 *  @param discloseType
	 */
	@ResponseBody
	@RequestMapping(value = "/changeDump", method = RequestMethod.POST)
	public Json changeDump(
			String discloseId, String mxcode, String mxname,String discloseType,
			HttpServletRequest request,HttpServletResponse response, ModelMap model) {
		Json json = new Json();
		Disclose disclose = null;
		try{
			if (discloseId != null && !"".equals(discloseId)) {
				disclose = discloseServiceImpl.selectById(discloseId);
				mxname = reportRegionServiceImpl.selectById(mxcode).getRegionName();
				disclose.setMxcode(DESFileUtil.encryptStr(mxcode));
				disclose.setMxname(DESFileUtil.encryptStr(mxname));
				discloseServiceImpl.updateById(disclose);
				json.setSuccess(true);
				json.setMsg("数据转储成功！");
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e);
			json.setSuccess(true);
			json.setMsg("数据转储失败！");
		}
		
		return json;
	}
	

	/**
     * 删除
     * @param ids
     * @return
     */
	@RequestMapping(value = "/discloseDelete", method = { RequestMethod.POST, RequestMethod.GET })
	public String discloseDelete(
			@RequestParam(value = "ids", required = true) String ids,
			HttpServletRequest request, HttpServletResponse response, ModelMap model) {
		String[] idArr = ids.split(",");
		
		List<Disclose> entityList = new ArrayList<Disclose>();
		List<String> list = new ArrayList<String>();
		if(idArr.length > 0 ){
			
			for(int i = 0; i < idArr.length;i++){
				list.add(idArr[i]);
			}
			entityList = discloseServiceImpl.selectBatchIds(list);
			for(Disclose disclose :entityList){
				disclose.setRemoveFlag(1);
			}
			discloseServiceImpl.updateBatchById(entityList);
		}
		
		//discloseServiceImpl.deleteBatchIds(Arrays.asList(idArr));
		model.addAttribute("flag", "数据删除成功！");
		return "redirect:discloseList";
	}     

	
	/**
     * 查看举报回复页面
     * @return
     */
	@RequestMapping(value = "/reportResponseForm", method = RequestMethod.GET)
	public String reportResponseForm(String discloseId,HttpServletRequest request) {
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("rUid", discloseId);
		String userName = this.getUserName();
		map.put("rUname", userName);
		String userId = this.getUserID();
		map.put("rUserId", userId);
		//回复时间
		String ctime = GTime.getTime(GTime.YYYY_MM_DDHHMMS);
		map.put("rDate", ctime);
		//自动生成ID查询码
        String guid = IdWorker.get32UUID();
        map.put("responseId", "");
		
		request.setAttribute("formData",map);
		
		return "/report/reportResponse/reportResponseForm";
	}
    
    /**
     * 保存举报回复信息
     * @return
     */
	@RequestMapping(value = "/reportResponseSave", method = RequestMethod.POST)
	public String reportResponseSave(
			String responseId, ReportResponse reportResponse, 
			HttpServletRequest request,HttpServletResponse response, ModelMap model) {
		try {
			if (!StringUtils.isBlank(responseId)) {
				model.addAttribute("flag", "数据修改成功！");
				reportResponse.setRContent(DESFileUtil.encryptStr(reportResponse.getRContent()));
				reportResponseServiceImpl.updateById(reportResponse);
			} else {
			
				reportResponseServiceImpl.insert(reportResponse);
				String discloseId = reportResponse.getRUid();
				if (!StringUtils.isBlank(discloseId)) {
					Disclose disclose = discloseServiceImpl.selectById(discloseId);
					disclose.setReplyUserId(DESFileUtil.encryptStr(reportResponse.getRUserId()));
					disclose.setReplyUname(DESFileUtil.encryptStr(reportResponse.getRUname()));
					disclose.setReplyContent(DESFileUtil.encryptStr(reportResponse.getRContent()));
					disclose.setReplyDate(DESFileUtil.encryptStr(reportResponse.getRDate()));
					discloseServiceImpl.updateById(disclose);
				}
				model.addAttribute("flag", "数据添加成功！");
			}
		} catch (Exception e) {
			e.printStackTrace();
			logger.error(e);
		}
		return "redirect:reportResponseList";
	}

    @ResponseBody
	@RequestMapping(value = "/discloseAjax", method = RequestMethod.POST)
	public Json discloseAjax(String discloseId) {
		Disclose disclose = discloseServiceImpl.selectById(discloseId);
		Json json = new Json();
		json.setSuccess(true);
		json.setObj(disclose);
		return json;
	}
	
	@RequestMapping(value = "/discloseExportExcel", method = { RequestMethod.GET, RequestMethod.POST })
	public void discloseExportExcel(
			Disclose disclose,
			HttpServletRequest request, HttpServletResponse response, ModelMap model) {
		
		EntityWrapper<Disclose> entityWrapper = new EntityWrapper<Disclose>();
		
	    if(StringUtils.isNotBlank(disclose.getDiscloseId())){
			entityWrapper.like("disclose_id", disclose.getDiscloseId());
		}
		model.addAttribute("discloseId", disclose.getDiscloseId());
																															
		List<Disclose> resultList = discloseServiceImpl.selectList(entityWrapper);
		
		ExportUtil.export(request, response, resultList,"导出Excel","disclose", 0, 2, 0, 16);
	}
	
	
	/** 
     * 获取对象的所有属性值，对对象数据进行加密或者解密然后返回该对象 
	 * @throws SecurityException 
	 * @throws NoSuchFieldException 
	 * 加密状态desState:0加密 1解密
	 * 
     * */  
    public Disclose DiscloseEncryptAndDecrypt(Disclose o,String desState) {  
    	 
    	Disclose obj = new Disclose();
    	String[] fieldNames= DesModleUtils.getFiledName(o);  
	    Object[] value=new Object[fieldNames.length]; 
	     
	     for(int i=0;i<fieldNames.length;i++){  
	    	 if("serialVersionUID".equals(fieldNames[i])){
	    		 continue;
	    	 }
	         value[i] = DesModleUtils.getFieldValueByName(fieldNames[i], o); 
	         try {
				Field field = Disclose.class.getDeclaredField(fieldNames[i]);
				field.setAccessible(true);
				//获取当前属性的  类型
				String type = field.getType().toString();
				if("class java.lang.String".equals(type) && !"discloseId".equals(fieldNames[i])&& !"dateOrder".equals(fieldNames[i])){
					String str = "";
					if(StringUtils.isNotBlank((String) value[i])){
						if("0".equals(desState)){
							//加密对象值
							str = DESFileUtil.encryptStr((String) value[i]);
						}else{
							//解密对象值
							str = DESFileUtil.decryptStr((String) value[i]);
						}
						
					}
					field.set(obj, str);
				}else{
					field.set(obj, value[i]);
				}
				
			} catch (Exception e) {
				e.printStackTrace();
			}
	     }  

	     return obj;  
    } 
}
